package com.example.combwyaq.mvp.presenter;

import android.util.Log;

import com.blankj.utilcode.util.LogUtils;
import com.example.combwyaq.entity.UserEntity;
import com.example.combwyaq.mvp.contract.PersonalDetailsConteract;
import com.example.combwyaq.mvp.model.entity.BaseEntity;
import com.example.combwyaq.mvp.model.entity.UpLoadEntity;
import com.example.combwyaq.utils.ToastUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class PersonalDetailsPresenter extends BasePresenter<PersonalDetailsConteract.IPersonalModel,PersonalDetailsConteract.IPersonalView> {

    @Inject
    public PersonalDetailsPresenter(PersonalDetailsConteract.IPersonalModel iPersonalModel, PersonalDetailsConteract.IPersonalView iPersonalView) {
        super(iPersonalModel, iPersonalView);
    }
    public void requestUpDataUser(List<UserEntity> list){
        int sex;
        String name="";
        LogUtils.json(list);
        Map<String,Object> map=new HashMap<>();
        if (list.get(0).getUser_sex().equals("男")){
            sex=0;
        }else if (list.get(0).getUser_sex().equals("女")){
            sex=1;
        }else{
            sex=2;
        }
        if (list.get(0).getUser_name().equals("")){
            name="111";
        }else{
            name=list.get(0).getUser_name();
        }
        map.put("user_id",list.get(0).getUser_id());
        map.put("user_img",list.get(0).getUser_img());
        map.put("user_integral",1);
        map.put("user_name", name);
        map.put("user_phone",list.get(0).getUser_phone());
        map.put("user_pwd",list.get(0).getUser_pwd());
        map.put("user_sex",sex);
        m.request(map).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(this);


    }


    @Override
    public void onNext(BaseEntity baseEntity) {
        Log.i("onNext", "onNext: ");
            v.refreshView(baseEntity);

    }
}
